
package com.kweative.format;

import com.kweative.type.Node;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringReader;
import java.io.StringWriter;

/**
 *
 * @author henrik
 */
abstract public class Format {
	abstract public Node parse(InputStream xmlin);
	abstract public void serialize(Node node,OutputStream xmlout) throws Exception;

	public String serialize(Node node) throws Exception {
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		this.serialize(node, out);
		return out.toString();
	}
	public Node parse(String xml) {
		ByteArrayInputStream in = new ByteArrayInputStream(xml.getBytes());
		return this.parse(in);
	}
	public Node parse(File file) throws FileNotFoundException, IOException {
		FileInputStream in = new FileInputStream(file);
		Node result = this.parse(in);
		in.close();
		return result;
	}
}
